<template>
  <div class="topper">
    <div class="wrapper">
      <div class="left-bar">
        <div class="back-home divider">
          <em></em><router-link tag="a" to="index">商城首页</router-link>
        </div>
        <div class="item"><a href="">商家中心</a></div>
      </div>
      <div class="right-bar" v-if="user">
        <div class="login-user sub-menu">
          <router-link tag="a" class="menu-hd" to="userAccount">{{user.userNickname}}<em></em></router-link>
          <div class="down">
            <a href="">内容</a>
            <a href="">内容</a>
            <a href="">内容</a>
          </div>
        </div>
        <div class="item"><a href="">消息</a></div>
        <div class="logout divider"><a @click="logout">退出</a></div>
        <span class=""></span>
        <div class="cart"><em></em><router-link tag="a" to="cart">购物车</router-link></div>
        <div class="order"><em></em><a href="">我的订单</a></div>
        <div class="fav"><em></em><a href="">我的收藏</a></div>
        <div class="help"><em></em><a href="">帮助中心</a></div>
      </div>
      <div class="right-bar" v-else>
        <div class="logout divider"><router-link tag="a" to="/login">登陆</router-link></div>
      </div>
    </div>
  </div>
</template>
<script>
import http from '../base/api/http'
export default{
  name: 'Topper',
  data () {
    return {
      user: null
    }
  },
  methods: {
    getUser () {
      http.requestQuickGet('/java/api/user/getUserTopper').then(res => {
        if (res.status === 0) {
          this.user = res.data
        } else {
          this.user = null
        }
      })
    },
    logout () {
      this.$cookies.remove('CHANGFENG-USER')
      this.$router.go(0)
    }
  },
  mounted () {
    this.getUser()
  }
}
</script>
<style>

</style>
